﻿#pragma once
#include "ViewModelBase.h"
#include "MainPageViewModel.g.h"


namespace winrt::NovelReader::implementation
{
    struct MainPageViewModel : MainPageViewModelT<MainPageViewModel, NovelReader::implementation::ViewModelBase>
    {
        MainPageViewModel();

        winrt::Microsoft::UI::Xaml::Visibility ContentsVisibility() const; 
        void SetContentsVisibility(winrt::Microsoft::UI::Xaml::Visibility value);

        winrt::Windows::Foundation::Collections::IVector<winrt::NovelReader::Chapter> BookChapters();
        void BookChapters(winrt::Windows::Foundation::Collections::IVector<winrt::NovelReader::Chapter> const& value);

        winrt::hstring DisplayText() const; 
        void DisplayText(winrt::hstring const& value); 

        winrt::event_token DisplayTitleChanged(winrt::NovelReader::StringActionHandler const& handler);
        void DisplayTitleChanged(winrt::event_token const& token) noexcept;
        
        winrt::NovelReader::Chapter SelectedChapter(); 
        void SelectedChapter(winrt::NovelReader::Chapter const& value); 

        double FontSize() const; 
        winrt::Microsoft::UI::Xaml::Media::FontFamily FontFamily() const; 
        winrt::Microsoft::UI::Xaml::Style ThemeStyle() const; 

        bool IsLoading(); 
        void IsLoading(bool value); 
        

    private: 
        void UpdateDisplayTitle(winrt::hstring const& chapterTitle); 
        winrt::fire_and_forget LoadChapters(bool isNewFile);
        void OnSettingsChanged(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventArgs const& args);

        winrt::Microsoft::UI::Xaml::Visibility m_contentsVisibility; 
        winrt::Windows::Foundation::Collections::IVector<winrt::NovelReader::Chapter> m_bookChapters{ nullptr };
        winrt::hstring m_displayText; 
        winrt::hstring m_bookName; 
        winrt::hstring m_chapterTitle;
        winrt::event<winrt::NovelReader::StringActionHandler> m_displayTitleChanged; 
        winrt::NovelReader::Chapter m_selectedChapter{ nullptr }; 
        winrt::NovelReader::Settings m_userSettings{ nullptr }; 
        bool m_isLoading{ false }; 
    };
}
namespace winrt::NovelReader::factory_implementation
{
    struct MainPageViewModel : MainPageViewModelT<MainPageViewModel, implementation::MainPageViewModel>
    {
    };
}
